package com.homepig.httpclient.Chapter1;

import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class HttpClient1 {
    public void testHttpGet() throws IOException, URISyntaxException {
        //
        CloseableHttpClient httpClient = HttpClients.createDefault();

        HttpGet httpGet = new HttpGet("http://managerandroid.dev.91haolei.net/manager-android/ems/getemstrackv300?com=sto&adminId=100&no=3338750230558");
        //封装访问地址
        //URI uri = new URIBuilder("http://managerandroid.dev.91haolei.net/manager-android/ems/getemstrackv300").build();

        URIBuilder uriBuilder = new URIBuilder();
        uriBuilder = uriBuilder.setScheme("");
        uriBuilder = uriBuilder.setHost("");
        uriBuilder = uriBuilder.setPort(8080);
        uriBuilder = uriBuilder.setPath("");

        URI uri = URIUtils.createURI("http","",8080,"","","");
        //执行请求获取返回结果
        CloseableHttpResponse response = httpClient.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (200 == statusCode) {
            HttpEntity httpEntity = response.getEntity();
            EntityUtils.consume(httpEntity);
        }
        response.close();
    }

    public void testHttpPost(){
        CloseableHttpClient httpClient = HttpClients.createDefault();

    }

    public static void main(String[] args) {
        HttpClient1 httpClient1 = new HttpClient1();
        try {
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
